package com.liyu.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liyu.domain.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class BookDaoTestCase {
    @Autowired
    private BookDao bookDao;

    @Test
    public void selectById(){
        System.out.println(bookDao.selectById(1));
    }

    @Test
    public void testSave(){
        Book book = new Book();
        book.setType("测试数据1");
        book.setName("测试数据2");
        book.setDescription("测试数据3");
        bookDao.insert(book);

    }

    @Test
    public void testUpdate(){
        Book book = new Book();
        book.setId(4);
        book.setType("修改测试数据1");
        book.setName("测试数据2");
        book.setDescription("测试数据3");
        bookDao.updateById(book);

    }

    @Test
    void testDelete(){
        bookDao.deleteById(4);
    }

    @Test
    void selectAll(){
        List<Book> bookList = bookDao.selectList(null);
        for (Book book : bookList) {
            System.out.println(book);
        }
    }


    @Test
    void testGetPage() {
        IPage page = new Page(1, 5);
        bookDao.selectPage(page,null);
    }
    @Test
    void testGetBy() {
        QueryWrapper<Book> qw = new QueryWrapper<>();
        qw.like("name", "Java");
        bookDao.selectList(qw);
    }



}
